package com.micromsg.common.util;

import org.jasypt.util.password.BasicPasswordEncryptor;

public class PasswordUtil {

    private static final String SALT = "mysalt";
    private static final BasicPasswordEncryptor PASSWORD_ENCRYPTOR = new BasicPasswordEncryptor();

    /**
     * 生成安全密码
     *
     * @param password 明文密码
     * @return 密文密码
     */
    public static String encryptedPassword(String password) {
        //String password = "mypassword";
        //String salt = "mysalt";
        //BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
        String encryptedPassword = PASSWORD_ENCRYPTOR.encryptPassword(password + SALT);
        return encryptedPassword;
    }

    /**
     * 验证密码
     *
     * @param inputPassword     明文密码
     * @param encryptedPassword 密文密码
     * @return 验证成功返回true
     */
    public static boolean checkPassword(String inputPassword, String encryptedPassword) {
        //String inputPassword = "mypassword";
        //String salt = "mysalt";
        //BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
        boolean result = PASSWORD_ENCRYPTOR.checkPassword(inputPassword + SALT, encryptedPassword);
        return result;
    }
}
